package joe.beer;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class ProfileActivity extends Activity {

	EditText et;
	RadioButton rb_m;
	RadioButton rb_f;
	int mf;
	
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.profile_layout);
		Button b = (Button) findViewById(R.id.button1);
		
		// setup to get values from ui controls
		et = (EditText) findViewById(R.id.editText1);
		rb_f = (RadioButton) findViewById(R.id.radio0);
		rb_m = (RadioButton) findViewById(R.id.radio1);
		
		b.setOnClickListener(l);
	}
	
	private OnClickListener l = new OnClickListener() {
		public void onClick(View v) {
			
			// set sex value
			if (rb_m.isChecked())
				mf = 1;
			else
				mf = 0;
			
			finish();
		}
	};

	@Override
	public void finish() {
		Intent data = new Intent();
		data.putExtra("sex", mf);
		
		String test = et.getText().toString();
		
		data.putExtra("weight", test);//textView.getText().toString());
		
		if (test.isEmpty())
		{
			AlertDialog ad = new AlertDialog.Builder(this).create();
			ad.setCancelable(false); // This blocks the 'BACK' button
			ad.setMessage("Please enter a valid weight");
			ad.setButton("OK", new DialogInterface.OnClickListener() {
			    public void onClick(DialogInterface dialog, int which) {
			        dialog.dismiss();                    
			    }
			});
			ad.show();
		}
		else
		{
			setResult(RESULT_OK, data);
			super.finish();
		}
	}
}
